package com.dailyblue.java.project.bookstore.handler;

import com.dailyblue.java.project.bookstore.exception.ErrorPasswordException;
import com.dailyblue.java.project.bookstore.exception.ExistException;
import com.dailyblue.java.project.bookstore.exception.NotFoundUsernameException;
import com.dailyblue.java.project.bookstore.exception.NotLoginException;
import com.dailyblue.java.project.bookstore.util.JsonResult;
import com.dailyblue.java.project.bookstore.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public JsonResult exception(Exception e) {
        log.error(e.getMessage());
        return ResultTool.fail();
    }

    @ExceptionHandler(NotFoundUsernameException.class)
    public JsonResult notFountUsername(Exception e) {
        log.error(e.getMessage());
        return ResultTool.fail(e.getMessage());
    }

    @ExceptionHandler(ErrorPasswordException.class)
    public JsonResult ErrorPassword(Exception e) {
        log.error(e.getMessage());
        return ResultTool.fail(e.getMessage());
    }

    @ExceptionHandler(NotLoginException.class)
    public JsonResult notLogin(Exception e) {
        log.error(e.getMessage());
        return ResultTool.fail(e.getMessage());
    }

    @ExceptionHandler(ExistException.class)
    public JsonResult exist(Exception e) {
        log.error(e.getMessage());
        return ResultTool.fail(e.getMessage());
    }
}
